package cn.wolfcode.car.business.service.impl;


import cn.wolfcode.car.business.domain.Salary;
import cn.wolfcode.car.business.mapper.SalaryMapper;
import cn.wolfcode.car.business.query.SalaryQueryObject;
import cn.wolfcode.car.business.service.ISalaryService;
import cn.wolfcode.car.common.base.page.TablePageInfo;
import cn.wolfcode.car.common.util.Convert;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.List;

@Service
@Transactional
public class SalaryServiceImpl implements ISalaryService {

    @Autowired
    private SalaryMapper salaryMapper;


    @Override
    public TablePageInfo<Salary> query(SalaryQueryObject qo) {
        PageHelper.startPage(qo.getPageNum(), qo.getPageSize());
        return new TablePageInfo<>(salaryMapper.selectForList(qo));
    }


    @Override
    public void save(Salary salary) {
        BigDecimal realSalary = salary.getBasicSalary().add(salary.getMeritSalary()).subtract(salary.getDeductMoney());
        salary.setRealSalary(realSalary);
        salaryMapper.insert(salary);
    }

    @Override
    public Salary get(Long id) {
        return salaryMapper.selectByPrimaryKey(id);
    }


    @Override
    public void update(Salary salary) {
        salaryMapper.updateByPrimaryKey(salary);
    }

    @Override
    public void deleteBatch(String ids) {
        Long[] dictIds = Convert.toLongArray(ids);
        for (Long dictId : dictIds) {
            salaryMapper.deleteByPrimaryKey(dictId);
        }
    }

    @Override
    public List<Salary> list() {
        return salaryMapper.selectAll();
    }



}
